#    Tichy
#
#    copyright 2008 Guillaume Chereau (charlie137@gmail.com)
#
#    This file is part of Tichy.
#
#    Tichy is free software: you can redistribute it and/or modify it
#    under the terms of the GNU General Public License as published by
#    the Free Software Foundation, either version 3 of the License, or
#    (at your option) any later version.
#
#    Tichy is distributed in the hope that it will be useful, but
#    WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
#    General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with Tichy.  If not, see <http://www.gnu.org/licenses/>.

__docformat__ = 'reStructuredText'

import tichy


class TelNumber(tichy.Str):
    """Telephone number class"""

    def __init__(self, text='', **kargs):
        if not all(x in '#*0123456789' for x in text):
            raise ValueError('not a valid number : %s' % text)
        super(TelNumber, self).__init__(text, **kargs)

    def input_method(self):
        return 'number'

    def edit(self, parent=None, name='number', **kargs):
        text_edit = tichy.TextEditService.get()
        return text_edit.edit(parent, self, input_method='number',
                              name=name, **kargs)
